my_set = {"传智教育", "黑马程序员", "itheima", "传智教育", "黑马程序员", "itheima", "传智教育", "黑马程序员", "itheima"}
my_set_empty = set()
print(f"my_set的内容是：{my_set},类型是：{type(my_set)}")
print(f"my_set_empty的内容是：{my_set_empty},类型是：{type(my_set_empty)}")

my_set.add("Python")
my_set.add("传智教育")
print(my_set)

my_set.remove("黑马程序员")
print(my_set)


# 随机取出一个元素
my_set = {"传智教育", "黑马程序员", "itheima"}
element = my_set.pop()
print(element)
print(my_set)

my_set.clear()
print(my_set)

# 集合的差集
set1 = {1, 2, 3}
set2 = {1, 5, 6}
set3 = set1.difference(set2) # set1 - set2
print(f"取差集后的结果是：{set3}")

# 消除差集
set1 = {1, 2, 3}
set2 = {1, 5, 6}
set1.difference_update(set2)
print(set1)
print(set2)

# 合并集合
set1 = {1, 2, 3}
set2 = {1, 5, 6}
set3 = set1.union(set2)  # set1 + set2
print(set3)

ll = len(set1)
print(ll)

# 注意：集合不支持while循环遍历
# 可以利用for循环遍历
set1 = {1, 2, 3, 4, 5}
for element in set1:
    print({element}, end=' ')
